<!--$Id: scope.so,v 10.12 2007/06/14 17:41:59 bostic Exp $-->
<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Berkeley DB handles</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
</head>
<body bgcolor=white>
<a name="2"><!--meow--></a><a name="3"><!--meow--></a>
<table width="100%"><tr valign=top>
<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Programmer Notes</dl></b></td>
<td align=right><a href="../program/mt.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../program/namespace.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p align=center><b>Berkeley DB handles</b></p>
<p>The Berkeley DB library has a number of object handles.  The following table
lists those handles, their scope, and whether they are free-threaded
(that is, whether multiple threads within a process can share them).</p>
<br>
<b><a href="../../api_c/env_class.html">DB_ENV</a></b><ul compact><li>The <a href="../../api_c/env_class.html">DB_ENV</a> handle, created by the <a href="../../api_c/env_class.html">db_env_create</a> method, refers
to a Berkeley DB database environment -- a collection of Berkeley DB subsystems,
log files and databases.  <a href="../../api_c/env_class.html">DB_ENV</a> handles are free-threaded if
the <a href="../../api_c/env_open.html#DB_THREAD">DB_THREAD</a> flag is specified to the <a href="../../api_c/env_open.html">DB_ENV-&gt;open</a> method when
the environment is opened.  The handle should not be closed while any
other handle remains open that is using it as a reference (for example,
<a href="../../api_c/db_class.html">DB</a> or <a href="../../api_c/txn_class.html">DB_TXN</a>).  Once either the <a href="../../api_c/env_close.html">DB_ENV-&gt;close</a> or
<a href="../../api_c/env_remove.html">DB_ENV-&gt;remove</a> methods are called, the handle may not be accessed again,
regardless of the method's return.</ul>
<b><a href="../../api_c/txn_class.html">DB_TXN</a></b><ul compact><li>The <a href="../../api_c/txn_class.html">DB_TXN</a> handle, created by the <a href="../../api_c/txn_begin.html">DB_ENV-&gt;txn_begin</a> method, refers to
a single transaction.  The handle is not free-threaded.  Transactions
may span threads, but only serially, that is, the application must
serialize access to the <a href="../../api_c/txn_class.html">DB_TXN</a> handles.  In the case of nested
transactions, since all child transactions are part of the same parent
transaction, they must observe the same constraints. That is, children
may execute in different threads only if each child executes serially.
<p>Once the <a href="../../api_c/txn_abort.html">DB_TXN-&gt;abort</a> or <a href="../../api_c/txn_commit.html">DB_TXN-&gt;commit</a> methods are called, the
handle may not be accessed again, regardless of the method's return.
In addition, parent transactions may not issue any Berkeley DB operations
while they have active child transactions (child transactions that
have not yet been committed or aborted) except for <a href="../../api_c/txn_begin.html">DB_ENV-&gt;txn_begin</a>,
<a href="../../api_c/txn_abort.html">DB_TXN-&gt;abort</a> and <a href="../../api_c/txn_commit.html">DB_TXN-&gt;commit</a>.</p></ul>
<b><a href="../../api_c/logc_class.html">DB_LOGC</a></b><ul compact><li>The <a href="../../api_c/logc_class.html">DB_LOGC</a> handle refers to a cursor into the log files.  The
handle is not free-threaded.  Once the <a href="../../api_c/logc_close.html">DB_LOGC-&gt;close</a> method is called,
the handle may not be accessed again, regardless of the method's
return.</ul>
<b><a href="../../api_c/mempfile_class.html">DB_MPOOLFILE</a></b><ul compact><li>The <a href="../../api_c/mempfile_class.html">DB_MPOOLFILE</a> handle refers to an open file in the shared
memory buffer pool of the database environment.  The handle is not
free-threaded.  Once the <a href="../../api_c/memp_fclose.html">DB_MPOOLFILE-&gt;close</a> method is called, the handle may
not be accessed again, regardless of the method's return.</ul>
<b><a href="../../api_c/db_class.html">DB</a></b><ul compact><li>The <a href="../../api_c/db_class.html">DB</a> handle, created by the <a href="../../api_c/db_class.html">db_create</a> method, refers to a
single Berkeley DB database, which may or may not be part of a database
environment.  <a href="../../api_c/db_class.html">DB</a> handles are free-threaded if the
<a href="../../api_c/env_open.html#DB_THREAD">DB_THREAD</a> flag is specified to the <a href="../../api_c/db_open.html">DB-&gt;open</a> method when the
database is opened or if the database environment in which the database
is opened is free-threaded.  The handle should not be closed while any
other handle that refers to the database is in use; for example,
database handles should be left open while cursor handles into the
database remain open, or transactions that include operations on the
database have not yet been committed or aborted.  Once the
<a href="../../api_c/db_close.html">DB-&gt;close</a>, <a href="../../api_c/db_remove.html">DB-&gt;remove</a>, or <a href="../../api_c/db_rename.html">DB-&gt;rename</a> methods are
called, the handle may not be accessed again, regardless of the method's
return.</ul>
<b><a href="../../api_c/dbc_class.html">DBC</a></b><ul compact><li>The <a href="../../api_c/dbc_class.html">DBC</a> handle refers to a cursor into a Berkeley DB database.  The
handle is not free-threaded.  Cursors may span threads, but only
serially, that is, the application must serialize access to the
<a href="../../api_c/dbc_class.html">DBC</a> handles.  If the cursor is to be used to perform operations
on behalf of a transaction, the cursor must be opened and closed within
the context of that single transaction.  Once <a href="../../api_c/dbc_close.html">DBcursor-&gt;close</a> has been
called, the handle may not be accessed again, regardless of the
method's return.</ul>
<br>
<table width="100%"><tr><td><br></td><td align=right><a href="../program/mt.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../program/namespace.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
</body>
</html>
